package com.ruoyi.bbs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.bbs.domain.BbsSetting;
import com.ruoyi.bbs.service.IBbsSettingService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 社区设置Controller
 * 
 * @author saruri
 * @date 2024-10-02
 */
@RestController
@RequestMapping("/setting")
public class BbsSettingController extends BaseController
{
    @Autowired
    private IBbsSettingService bbsSettingService;

    /**
     * 查询社区设置列表
     */
    @RequiresPermissions("bbs:setting:list")
    @GetMapping("/list")
    public TableDataInfo list(BbsSetting bbsSetting)
    {
        startPage();
        List<BbsSetting> list = bbsSettingService.selectBbsSettingList(bbsSetting);
        return getDataTable(list);
    }

    /**
     * 导出社区设置列表
     */
    @RequiresPermissions("bbs:setting:export")
    @Log(title = "社区设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BbsSetting bbsSetting)
    {
        List<BbsSetting> list = bbsSettingService.selectBbsSettingList(bbsSetting);
        ExcelUtil<BbsSetting> util = new ExcelUtil<BbsSetting>(BbsSetting.class);
        util.exportExcel(response, list, "社区设置数据");
    }

    /**
     * 获取社区设置详细信息
     */
    @RequiresPermissions("bbs:setting:query")
    @GetMapping(value = "/{settingKey}")
    public AjaxResult getInfo(@PathVariable("settingKey") String settingKey)
    {
        return success(bbsSettingService.selectBbsSettingBySettingKey(settingKey));
    }

    /**
     * 新增社区设置
     */
    @RequiresPermissions("bbs:setting:add")
    @Log(title = "社区设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BbsSetting bbsSetting)
    {
        return toAjax(bbsSettingService.insertBbsSetting(bbsSetting));
    }

    /**
     * 修改社区设置
     */
    @RequiresPermissions("bbs:setting:edit")
    @Log(title = "社区设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BbsSetting bbsSetting)
    {
        return toAjax(bbsSettingService.updateBbsSetting(bbsSetting));
    }

    /**
     * 删除社区设置
     */
    @RequiresPermissions("bbs:setting:remove")
    @Log(title = "社区设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{settingKeys}")
    public AjaxResult remove(@PathVariable String[] settingKeys)
    {
        return toAjax(bbsSettingService.deleteBbsSettingBySettingKeys(settingKeys));
    }
}
